package cn.lqz.bucttrain.controller;

import cn.lqz.bucttrain.annotations.PageQueryAutoFill;
import cn.lqz.bucttrain.pojo.dto.OrderCreateDTO;
import cn.lqz.bucttrain.pojo.dto.OrderPageQueryDTO;
import cn.lqz.bucttrain.pojo.dto.OrderStatisticDTO;
import cn.lqz.bucttrain.pojo.dto.OrderUpdateDTO;
import cn.lqz.bucttrain.pojo.vo.*;
import cn.lqz.bucttrain.service.OrderService;
import cn.lqz.bucttrain.utils.ResponseUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 订单
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    /**
     * 加载或查询订单
     * @param orderPageQueryDTO
     * @return
     */
    @PostMapping("/loadOrderList")
    @PageQueryAutoFill
    public ResponseVO<PageResultVO> loadOrderList(OrderPageQueryDTO orderPageQueryDTO){
        return ResponseUtils.success(orderService.loadOrderList(orderPageQueryDTO));
    }

    /**
     * 添加订单
     * @param orderCreateDTO
     * @return
     */
    @PostMapping("/addOrder")
    public ResponseVO addOrder(@RequestBody @Valid OrderCreateDTO orderCreateDTO){
        orderService.addOrder(orderCreateDTO);
        return ResponseUtils.success();
    }

    @PostMapping("/updateOrder")
    public ResponseVO updateOrder(@Valid OrderUpdateDTO orderUpdateDTO){
        orderService.updateOrder(orderUpdateDTO);
        return ResponseUtils.success();
    }

    @PostMapping("/deleteOrder")
    public ResponseVO deleteOrder(@NotNull Long orderId){
        orderService.deleteOrder(orderId);
        return ResponseUtils.success();
    }

    /**
     * 导出订单
     * @param orderVOList
     * @param response
     */
    @PostMapping("/exportOrderExcel")
    public void exportOrderExcel(@RequestBody List<OrderVO> orderVOList, HttpServletResponse response){
        orderService.exportOrderExcel(orderVOList,response);
    }

    /**
     * 统计订单数量
     * @param orderStatisticDTO
     * @return
     */
    @PostMapping("/orderNumStatistic")
    public ResponseVO<OrderStatisticNumVO> orderNumStatistic(OrderStatisticDTO orderStatisticDTO){
        return ResponseUtils.success(orderService.orderNumStatistic(orderStatisticDTO));
    }

    /**
     * 统计订单金额
     * @param orderStatisticDTO
     * @return
     */
    @PostMapping("/orderMoneyStatistic")
    public ResponseVO<OrderStatisticMoneyVO> orderMoneyStatistic(OrderStatisticDTO orderStatisticDTO){
        return ResponseUtils.success(orderService.orderMoneyStatistic(orderStatisticDTO));
    }
}
